﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using br.com.SistemaChamados;
using br.com.SistemaChamados.Controller;
using br.com.SistemaChamados.Model;
using br.com.SistemaChamados.Enum;


public partial class Pages_SectorMain : System.Web.UI.Page
{

    protected void gvSector_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        SectorController sectorController = new SectorController();
        Sector sector = new Sector();
        try
        {
            int id = Convert.ToInt32(e.CommandArgument);
            switch (e.CommandName)
            {
                case "ExcludeData":
                    sector.Id = id;
                    if (sectorController.DeleteSector(sector) == EnumGenericState.GENERIC_STATE_SUCCESS)
                    {
                        Response.Write(@"<script language='javascript'>alert('Setor excluído com sucesso!');</script>");
                        Response.Redirect("SectorMain.aspx");
                    }
                    else
                    {
                        Response.Write(@"<script language='javascript'>alert('Ocorreu um erro durante a exclusão, por favor tente novamente!');</script>");
                    }
                    break;

                case "UpdateData":
                    Session["SectorIdToUpdate"] = id;
                    Response.Redirect("SectorUpdate.aspx");
                    break;
            }
        }
        catch (Exception ex)
        {
            Response.Write(@"<script language='javascript'>alert('Ocorreu um erro ao deletar o setor: <br>" + ex.Message + ".');</script>");
            sector = null;
            sectorController = null;
        }
    }
}